package meta.api.web.account.conf;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import meta.api.web.common.presentation.interceptor.ApiAuthChkInterceptor;
import meta.api.web.common.presentation.interceptor.ApiCorsInterceptor;
import meta.common.util.SpringUtil;

@Configuration
public class AccountWebMvcConfig implements WebMvcConfigurer {

    private static final String PATH_PREFIX = "/api/account";

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(SpringUtil.getBean(ApiCorsInterceptor.class, "apiCorsInterceptor"))
                .addPathPatterns(PATH_PREFIX + "/**");

        registry.addInterceptor(SpringUtil.getBean(ApiAuthChkInterceptor.class, "apiAuthChkInterceptor"))
                .addPathPatterns(PATH_PREFIX + "/**")
                .excludePathPatterns(
                        PATH_PREFIX + "/signup/options",
                        PATH_PREFIX + "/captcha",
                        PATH_PREFIX + "/email",
                        PATH_PREFIX + "/signup",
                        PATH_PREFIX + "/login",
                        PATH_PREFIX + "/profile",
                        PATH_PREFIX + "/password/update");
    }
}
